//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     // Initially set via a loop in the UFO script
private alias Object.Value1 : Object.ToyFreddyTimer     // Initially set via a loop in the UFO script
private alias Object.Value3 : Object.ToyFreddyRandom    // Initially set via a loop in the UFO script
private alias Object.Value4 : Object.ToyFreddyAI    // Initially set via a loop in the UFO script
private alias Object.Value5 : Object.ScareTimer    // Initially set via a loop in the UFO script

private alias Object.Value6 : Object.ToyFreddyRise    // Initially set via a loop in the UFO script
private alias Object.Value7 : Object.MoveTime    // Initially set via a loop in the UFO script
private alias Object.Value8 : Object.HeadShake    // Initially set via a loop in the UFO script

private alias object[6].value17 : CamGame.State
private alias object[6].value18 : CamGame.Camera
private alias object[6].value19 : CamGame.Static
private alias object[6].value20 : CamGame.Dead

private alias Object.Value10 : Object.Cooldown    // Initially set via a loop in the UFO script
private alias Object.Value11 : Object.Tweak    // Initially set via a loop in the UFO script
private alias Object.Value12 : Object.GameLocation    // Initially set via a loop in the UFO script



// Game Mode Aliases
public value OfficePower = 100;

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 0 : CAM_SHOWSTAGE_0
private alias 1 : CAM_DININGHALL_1
private alias 2 : CAM_BACKSTAGE_2
private alias 3 : CAM_PIRATESCOVE_3
private alias 4 : CAM_WESTHALL_4
private alias 5 : CAM_CLOSET_5
private alias 6 : CAM_WHALLCORNER_6
private alias 7 : CAM_EASTHALL_7
private alias 8 : CAM_EHALLCORNER_8
private alias 9 : CAM_KITCHEN_9
private alias 10 : CAM_BATHROOMS_10

private alias 15 : ToyFreddy_OFFICEDOOR
private alias 16 : ToyFreddy_WAITTOSCARE
private alias 17 : ToyFreddy_SCARE


private alias 0  : MRHUGS_LEFT
private alias 1  : MRHUGS_RIGHT
private alias 2  : MRHUGS_TOP


private alias object.state : ToyFreddy.State



event ObjectMain
//-1 is basically the ai level 0 ig
if Object[5].Type == TypeName[Blank Object]
	switch ToyFreddy.state
		case 0
			if object.Cooldown > 0
				object.Cooldown--
			end if	

			if object.Cooldown == 0
				Object.ToyFreddyTimer++
				Object.MoveTime = 500
				rand(temp3, 50)
				Object.MoveTime += temp3
				if Object.ToyFreddyTimer >= Object.MoveTime 
					Rand(Object.ToyFreddyRandom, 21)
					if Object.ToyFreddyAI > Object.ToyFreddyRandom 
						rand(Object.GameLocation, 3)
						switch Object.GameLocation
							case 0
								CamGame.State = MRHUGS_LEFT
								object.state = 1
								CamGame.Static = 5
							break
							case 1
								CamGame.State = MRHUGS_RIGHT
								object.state = 1
								CamGame.Static = 5
							break
							case 2
								CamGame.State = MRHUGS_TOP
								object.state = 1
								CamGame.Static = 5
							break														
						end switch
					end if
					Object.ToyFreddyTimer = 0
				end if	
			end if
		break
		case 1
			Object.ToyFreddyTimer++
			Object.MoveTime = 600
			rand(temp3, 50)
			Object.MoveTime += temp3
			if Object.ToyFreddyTimer >= Object.MoveTime 
				Rand(Object.ToyFreddyRandom, 21)
				if Object.ToyFreddyAI > Object.ToyFreddyRandom 
					switch CamGame.State
						case MRHUGS_LEFT
							if GameLeftDoor == 1
								CamGame.State = -1
								PlaySfx(SfxName[Block], 0)
								CamGame.Static = 5
								object.Cooldown = 300
								object.state = 0
							else
								CamGame.Dead = 1
								object.state++	
							end if
						break
						case MRHUGS_RIGHT
							if GameRightDoor == 1
								CamGame.State = -1
								PlaySfx(SfxName[Block], 0)
								CamGame.Static = 5
								object.Cooldown = 300
								object.state = 0
							else
								CamGame.Dead = 1
								object.state++	
							end if						
						break
						case MRHUGS_TOP
							if GameMiddleDoor == 1
								CamGame.State = -1
								PlaySfx(SfxName[Block], 0)
								CamGame.Static = 5
								object.Cooldown = 300
								object.state = 0
							else
								CamGame.Dead = 1
								object.state++	
							end if						
						break
					end switch
				end if
				Object.ToyFreddyTimer = 0
			end if	
		break
		case 2
			Object.ToyFreddyTimer++
			Object.MoveTime = 400
			rand(temp3, 100)
			Object.MoveTime += temp3
			if Object.ToyFreddyTimer >= Object.MoveTime 
				StopMusic()
				PlaySfx(SfxName[Scream2], 0)				
				object.state = 17
			end if
		break
		case 17
			PlayerJumpscared = 1
			if Object.ToyFreddyRise > -100
				Object.ToyFreddyRise -= 16
			else
				Object.ToyFreddyRise = -100
			end if
		break
	end switch
end if	
end event

event ObjectDraw
//	rand(Object.GameLocation, 3)
//	DrawNumbers(0, 32, 96, Object.ToyFreddyTimer, 3, 8, 0)

//	DrawNumbers(0, 64, 96, CamGame.State, 3, 8, 0)

//	DrawNumbers(0, 96, 96, Object.ScareTimer, 3, 8, 0)



		rand(Object.HeadShake, 6)


	if ToyFreddy.state == 17
	
		
		temp1 = Screen.xsize
		temp1 /= 2
		temp1 -= 140


		temp1 += Object.HeadShake

		DrawSpriteScreenFX(10, FX_SCALE, temp1, Object.ToyFreddyRise)	//body
		DrawSpriteScreenFX(11, FX_SCALE, temp1, Object.ToyFreddyRise)	//head
	end if

	

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Jumpscares.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[24].Type = TypeName[ToyFreddy]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[24].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[24].DrawOrder = 5

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	
	SpriteFrame(0, 280, 298, 83, 1, 1252)
	SpriteFrame(46, 100, 206, 227, 1, 1024)	//11
	SpriteFrame(46, 100, 206, 227, 457, 643)	//11
	SpriteFrame(46, 100, 206, 227, 457, 643)	//13
	SpriteFrame(46, 100, 206, 227, 457, 643)	//11

end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
